import collections
class Solution(object):
    def nextBeautifulNumber(self, n):
        def judge(s):
            c = collections.Counter(s)
            flag = True
            for key in c:
                if int(key) != c[key]:
                    flag = False
                    break
            return flag
        num = n + 1
        while True:
            if judge(str(num)):
                return num
            else:
                num += 1



